﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

//小鸟控制器
public class Bird : MonoBehaviour {

	private Rigidbody2D rb2d;//刚体
	public float flyUP = 10f;//小鸟一次飞多高
	public static Bird initializa;
	private Animator anim;

	private void Awake() {
		if (initializa == null) {
			initializa = this;
		} else if (initializa != this) {
			Destroy(initializa);
		}
	}

	void Start() {
		rb2d = GetComponent<Rigidbody2D>();
		anim = GetComponent<Animator>();
	}

	void Update() {
		if (!GameController.initialize.gameIsOver) {
			//按下鼠标或者按下空格键，小鸟向上飞
			if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space)) {
				anim.SetTrigger("Flap");
				rb2d.velocity = new Vector2(0.0f, transform.position.y + flyUP);
			}
		}
	}
	public void Die() {
		GameController.initialize.gameIsOver = true;
		anim.SetTrigger("Die");
		rb2d.velocity = Vector2.zero;
	}
}
